All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----com.sun.java.swing.JComponent | +----com.sun.java.swing.JRootPane
The following image shows these relationships:
Note: The JComponent method getRootPane
can be used to
obtain the JRootPane that contains a given component.
![]() |
Although the menuBar component is optional, the layeredPane, contentPane, and glassPane always exist. Attempting to set them to null generates an exception.
The contentPane
must be the parent of any children of
the JRootPane. Rather than adding directly to a JRootPane, like this:
rootPane.add(child);You instead add to the contentPane of the JRootPane, like this:
rootPane.getContentPane().add(child);The same priniciple holds true for setting layout managers, removing components, listing children, etc. All these methods are invoked on the
contentPane
instead of on the JRootPane.
Note: The default layout manager for theIf a JMenuBar component is set on the JRootPane, it is positioned along the upper edge of the frame. ThecontentPane
is a BorderLayout manager. However, the JRootPane uses a custom LayoutManager. So, when you want to change the layout manager for the components you added to a JRootPane, be sure to use code like this:rootPane.getContentPane().setLayout(new BoxLayout());
contentPane
is
adjusted in location and size to fill the remaining area.
(The JMenuBar and the contentPane
are added to the
layeredPane
component at the JLayeredPane.FRAME_CONTENT_LAYER
layer.)
The layeredPane
is the parent of all children in the JRootPane.
It is an instance of JLayeredPane, which provides the ability to add components
at several layers. This capability is very useful when working with menu popups,
dialog boxes, and dragging -- situations in which you need to place a component
on top of all other components in the pane.
The glassPane
sits on top of all other components in the JRootPane.
That provides a convenient place to draw above all other components, and makes
it possible to intercept mouse events, which is useful both for dragging and
for drawing. Developers can use setVisible
on the glassPane
to control when the glassPane
displays over the other children.
By default the glassPane
is not visible.
The custom LayoutManager used by JRootPane ensures that:
glassPane
, if present, fills the entire viewable
area of the JRootPane (bounds - insets).
layeredPane
fills the entire viewable area of the
JRootPane. (bounds - insets)
menuBar
is positioned at the upper edge of the
layeredPane().
contentPane
fills the entire viewable area,
minus the MenuBar, if present.
If you replace the LayoutManager of the JRootPane, you are responsible for
managing all of these views. So ordinarily you will want to be sure that you
change the layout manager for the contentPane
rather than
for the JRootPane itself!
Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
protected JMenuBar menuBar
protected Container contentPane
protected JLayeredPane layeredPane
protected Component glassPane
protected JButton defaultButton
protected JRootPane. DefaultAction defaultPressAction
protected JRootPane. DefaultAction defaultReleaseAction
public JRootPane()
protected JLayeredPane createLayeredPane()
protected Container createContentPane()
protected Component createGlassPane()
protected LayoutManager createRootLayout()
public void setJMenuBar(JMenuBar menu)
public void setMenuBar(JMenuBar menu)
setJMenuBar(JMenuBar menu)
.
public JMenuBar getJMenuBar()
public JMenuBar getMenuBar()
getJMenubar()
.
public void setContentPane(Container content)
public Container getContentPane()
public void setLayeredPane(JLayeredPane layered)
public JLayeredPane getLayeredPane()
public void setGlassPane(Component glass)
public Component getGlassPane()
public boolean isValidateRoot()
Deferred requests to relayout a component and it's descendants, i.e. calls to revalidate(), are pushed upwards to either a JRootPane or a JScrollPane because both classes override isValidateRoot() to return true.
public void addNotify()
public void removeNotify()
public void setDefaultButton(JButton defaultButton)
public JButton getDefaultButton()
protected void addImpl(Component comp, Object constraints, int index)
public AccessibleContext getAccessibleContext()
All Packages Class Hierarchy This Package Previous Next Index